<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/common/common.jsp"%>
<html>
<head>
    <meta charset="utf-8" />
    <title>厅干部平时考核管理系统</title>
    <script type="text/javascript" src="<c:url value='/resource/jxkh/js/jquery.form.js'/>"></script>
    <style type="text/css">
        #jedatebox{z-index: 9999999999999999999999999999!important;}
    </style>
    <script>
        function tjSubmitForm() {
            $("#submit_form").ajaxSubmit({
                type: "post",
                dataType: "json",
                success: function (data) {
                    if (data.data.status == 1) {
                        showMessage("操作成功！");
                    } else {
                        showMessage(data.data.body);
                    }
                },
                error: function () {
                    showMessage("失败！");
                }
            });
        }
        $(function() {
            //下拉框
            $(document).click(function () {
                $(".row_select_xl").slideUp(200);
                $(".khybj_select_xl").slideUp(200);
            });
            $(".row_select").click(function (e) {
                e = e || window.event;
                if (e.stopPropagation) {
                    e.stopPropagation();
                } else {
                    e.cancelBubble = true;
                }
                $(this).children(".row_select_xl").slideToggle(200);
                $(this).parents("td").siblings("td").find(".row_select_xl").hide();
                var selecttext = $(this).children("p");
                var selectmain = $(this).children(".row_select_xl");
                var lis = selectmain.find('li');
                for (var i = 0; i < lis.length; i++) {
                    lis[i].onclick = function () {
                        selectmain.hide();
                        var textval = $(this).html();
                        selecttext.text(decodeURIComponent(textval));
                    }
                }
            });
            $(".row_select_xl li").click(function (e) {
                e = e || window.event;
                if (e.stopPropagation) {
                    e.stopPropagation();
                } else {
                    e.cancelBubble = true;
                }
                $(this).parents(".row_select_xl").hide();
            });
            //
            $(".khybj_select").click(function (e) {
                e = e || window.event;
                if (e.stopPropagation) {
                    e.stopPropagation();
                } else {
                    e.cancelBubble = true;
                }
                $(this).children(".khybj_select_xl").slideToggle(200);
                $(this).parents("td").siblings("td").find(".khybj_select_xl").hide();
                var selecttext = $(this).children("p");
                var selectmain = $(this).children(".khybj_select_xl");
                var lis = selectmain.find('li');
                for (var i = 0; i < lis.length; i++) {
                    lis[i].onclick = function () {
                        selectmain.hide();
                        var textval = $(this).html();
                        var value = $(this).val();
                        selecttext.text(decodeURIComponent(textval));
                        $(this).parents(".khybj_select").find("input[type=hidden]").val(value);
                        if($(this).parent().hasClass("khyul")){
                            $(".khlxslt").find("p").text("请选择");
                            $(".khlxslt").find("input[type=hidden]").val("");
                            $.ajax({
                                type: "GET",
                                url: "<c:url value="/khlx/findKhlxNameByItemaId.json"/>",
                                data: {itemaId:value},
                                dataType: "json",
                                success: function(rs){
                                    $(".khlxslt").find(".khybj_select_xl").empty();
                                    var s = rs.khlxNameList;
                                    var str ="";
                                    for(var i=0;i<s.length;i++){
                                        str = "<li value="+s[i].DBID+">"+s[i].NAME+"</li>";
                                        $(".khlxslt").find(".khybj_select_xl").append(str);
                                    }
                                    $(".khybj_select_xl li").click(function (e) {
                                        e = e || window.event;
                                        if (e.stopPropagation) {
                                            e.stopPropagation();
                                        } else {
                                            e.cancelBubble = true;
                                        }
                                        $(this).parents(".khybj_select_xl").hide();
                                    });
                                }
                            });
                        }
                    }
                }
            });
            $(".khybj_select_xl li").click(function (e) {
                e = e || window.event;
                if (e.stopPropagation) {
                    e.stopPropagation();
                } else {
                    e.cancelBubble = true;
                }
                $(this).parents(".khybj_select_xl").hide();
            });
            //下拉框结束

            //单选框
            $(".row_rt_main .checkbox").click(function () {
                $(this).addClass("checkbox_hov").siblings(".checkbox").removeClass("checkbox_hov");
            });
            //单选框结束
        });
    </script>
</head>
<body>
<div class="njga" style="overflow: auto;">
    <div class="bmkhcp" style="overflow: hidden">
            <div class="bmkhcp_lf" style="width: 100%;position: relative;">
                <div class="title">考核指标设置</div>
                <div class="rygl_rt_top khysz_top">
                    <div class="ul_bj" style="margin-right: 40px;margin-top: 20px;">
                        <div class="ul_bj_lf" id="khmc_bj">编辑</div>
                        <div class="ul_bj_lf" id="khmc_tj">添加</div>
                        <div class="ul_bj_lf ul_bj_rt" id="batch_delete">批量删除</div>
                    </div>
                </div>
                <div style="margin-top: 70px;"><table id="boot_table" ></table></div>
                <form action="<c:url value='/khmc/addKhmcInfo.json'/>" method="post" id="submit_form">
                    <!--考核类别添加-->
                    <div class="date_pop" id="fksz_pop_tj">
                        <div class="khybj">
                            <div class="row">
                                <div class="row_lf">考核域</div>
                                <div class="row_rt">
                                    <div class="row_rt_main_w">
                                        <div class="khybj_select">
                                            <p>请选择</p>
                                            <input type="hidden" name="itemaId"/>
                                            <div class="arrow_down"></div>
                                            <ul class="khybj_select_xl khyul">
                                                <c:forEach var="i" items="${khyNameList}">
                                                    <li value="${i.dbid}">${i.name}</li>
                                                </c:forEach>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="row_lf">考核类别</div>
                                <div class="row_rt">
                                    <div class="row_rt_main_w">
                                        <div class="khybj_select khlxslt">
                                            <p>请选择</p>
                                            <input type="hidden" name="itembId"/>
                                            <div class="arrow_down"></div>
                                            <ul class="khybj_select_xl" id="khmctj_select_xl">
                                                <c:forEach var="i" items="${khlxNameList}">
                                                    <li value="${i.dbid}">${i.name}</li>
                                                </c:forEach>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="row_lf">考核名称</div>
                                <div class="row_rt">
                                    <textarea rows="4" style="width: 80%;box-sizing: border-box;border: 1px solid #bdc4c9;border-radius: 4px;resize: none;color: #333;font-size: 14px;" name="name"></textarea>
                                </div>
                            </div>
                            <div class="row">
                                <div class="row_lf">分数</div>
                                <div class="row_rt">
                                    <div class="row_rt_main_w">
                                        <div class="row_rt_main">
                                            <input type="text"  placeholder="请输入" name="score"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="row_lf">状态</div>
                                <div class="row_rt">
                                    <input type="radio" name="status" value="1" checked="checked"/> 启用
                                    <input type="radio" name="status" style="margin-left: 10px;" value="0"/> 禁用
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--考核类别添加结束-->
                </form>
            </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        initTable();//初始化表格
        //全选与取消
        $("#chkAll").click(function() {
            $("[name=chkGuid]:checkbox").prop("checked", this.checked);
        });
        //当所有checkbox选中，全选选中
        $("[name=chkGuid]:checkbox").click(function() {
            var flag = true;
            $("[name=chkGuid]:checkbox").each(function() {
                if(!this.checked) {
                    flag = false;
                }
            });
            $("#chkAll").prop("checked", flag);
        });
        //考核类别添加
        $("#khmc_tj").click(function(){
            var open =  layer.open({
                type: 1, //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）。
                shift: 1, //动画    0-6     css3动画
                closeBtn: 1, //关闭按钮  0 不显示  style  1和2  标题为 false 2
                btn: ['确定','取消'],
                btn1: function(index, layero){
                    tjSubmitForm();
                },
                title: ['考核类别添加', 'background:#5f9ad1;color:#fff;text-align: left;font-size: 18px;'],
                area: ['560px', '500px'], //宽高
                content: $("#fksz_pop_tj") //iframe层-禁滚动条  $("#photosDemo").html()   'http://www.baidu.com/'
            });
        });
        $("#batch_delete").click(function() {
            var dbid = $(this).closest("tr").find("input[type=checkbox]").val();
            var arr = new Array();
            $("input[type=checkbox][name=chkGuid]:checked").each(function(){
                arr.push($(this).val());
            });
            var open = layer.open({
                /* type: 1,                                    //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）。
                 closeBtn: 1,       //关闭按钮  0 不显示  style  1和2  标题为 false 2*/
                btn: ['确定', '取消'],
                btn1: function (index, layero) {
                    $.ajax({
                        type: "GET",
                        url: "<c:url value="/khmc/batchDeleteKhmcInfo.json"/>",
                        data: {dbids:arr},
                        dataType: "json",
                        traditional: true,
                        success: function(rs){
                            if (rs.data.status == 1) {
                                showMessage("操作成功！");
                            } else {
                                showMessage(rs.data.body);
                            }
                        },
                        error: function(){
                            showMessage("失败！");
                        }
                    });
                },
                title: '信息'
                ,content:'确定删除吗'
            });
        });
    });
</script>
<script>
    var $table = $('#boot_table'),
            $remove = $('#remove'),
            selections = [];
    function initTable() {
        $table.bootstrapTable({
            idField: "id",
            pagination: "true",
            sidePagination: 'server',
            url: "<c:url value='/khmc/allKhmcInfo.json'/>",
            height: 550,
            columns: [
                /*{
                 field: 'ID',
                 checkbox: true,
                 align: 'center',
                 valign: 'middle'
                 }, */
                {
                    title: '<input type="checkbox" id="chkAll"/>',
                    field: 'DBID',
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                        var str = "<input type='checkbox' name='chkGuid' value="+ value + " />";
                        return str;
                    }
                }, {
                    title: '序号',
                    field: 'Number',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var page = $table.bootstrapTable("getOptions");
                        return ((page.pageNumber- 1 )* page.pageSize)+ index+1;
                    }
                }, {
                    title: '考核域',
                    field: 'KHYNAME',
                    align: 'center',
                    valign: 'middle'
                }, {
                    title: '考核类别',
                    field: 'KHLXNAME',
                    align: 'center',
                    valign: 'middle'/*,
                     formatter: function(value, row, index){

                     }*/
                }, {
                    field: 'NAME',
                    title: '考核名称',
                    align: 'center',
                }, {
                    field: 'SCORE',
                    title: '分值',
                    align: 'center',
                }, {
                    field: 'STATUS',
                    title: '状态',
                    align: 'center',
                    formatter: function(value, row, index){
                        switch(value)
                        {
                            case '0':
                                return "禁用";
                            case '1':
                                return "启用";
                        }
                    }
                }, {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    formatter: operateFormatter
                }

            ]
        });
    }
    function operateFormatter(value, row, index) {
        return [
            '<a href="javascript:editKhmc('+row.DBID+')" >编辑',
            '</a>  ',
            '<a href="javascript:delKhmc('+row.DBID+')" >删除',
            '</a>  '
        ].join('');

    }
    function getHeight() {
        return $(window).height() - $('h1').outerHeight(true);
    }
    //考核名称删除
    function delKhmc(dbid) {
        var open = layer.open({
            /*type: 1,                                    //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）。
            closeBtn: 1,       //关闭按钮  0 不显示  style  1和2  标题为 false 2*!/*/
            btn: ['确定', '取消'],
            btn1: function (index, layero) {
                $.ajax({
                    type: "GET",
                    url: "<c:url value="/khmc/deleteKhmcInfo.json"/>",
                    data: {dbid:dbid},
                    dataType: "json",
                    success: function(rs){
                        if (rs.data.status == 1) {
                            $('#boot_table').bootstrapTable('refresh');
                            showMessage("操作成功！");
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index);
                        } else {
                            showMessage(rs.data.body);
                        }
                    },
                    error: function(){
                        showMessage("失败！");
                    }
                });
            },
            title: '信息'
            ,content:'确定删除吗？'
        });
    }
    //考核名称删除结束
    //考核名称编辑
    function editKhmc(dbid) {
        var open =  layer.open({
            type: 2, //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）。
            shift: 1, //动画    0-6     css3动画
            closeBtn: 1, //关闭按钮  0 不显示  style  1和2  标题为 false 2
            btn: ['确定','取消'],
            btn1: function(index, layero){
                var newpsw = $(layero).find("iframe")[0].contentWindow;
                newpsw.submitForm();
            },
            title: ['考核名称编辑', 'background:#5f9ad1;color:#fff;text-align: left;font-size: 18px;'],
            area: ['560px', '500px'], //宽高
            content:"<c:url value='/khmc/findKhmcInfo.html?dbid='/>"+dbid //iframe层-禁滚动条  $("#photosDemo").html()   'http://www.baidu.com/'
        });
    }
    //考核类型编辑结束

    function showMessage(content) {
        layer.open({
            title: '信息'
            , content: content
        });
    }

</script>
</body>
</html>
